Array.prototype.last = function () {
  return this[this.length - 1];
};
Array.prototype.remove = function (it) {
  const index = this.indexOf(it);
  if (index > -1) {
    return this.splice(index, 1);
  }
};
Array.prototype.removeBy = function (fn) {
  const index = this.findIndex(fn);
  if (index > -1) {
    return this.splice(index, 1);
  }
};
export const uniqueArr = (arr: any[]) => {
  return Array.from(new Set(arr));
};
Array.prototype.distinct = function () {
  return uniqueArr(this);
};
Set.prototype.addAll = function (set: any[] | Set<any>) {
  set.forEach((i: any) => {
    this.add(i);
  });
  return this;
};

Set.prototype.find = function (fn) {
  for (const item of this) {
    if (fn(item)) {
      return item;
    }
  }
};

Map.prototype.filter = function (fn) {
  let res: any[] = [];
  for (const item of this.values()) {
    if (fn(item)) {
      res.push(item);
    }
  }
  return res;
};
Map.prototype.find = function (fn) {
  for (const item of this.values()) {
    if (fn(item)) {
      return item;
    }
  }
};
window.NODE_ENV = process.env.NODE_ENV;

// const fn = window.addEventListener;
// (window as any).addEventListener_ = fn;
// window.addEventListener = function(...res) {
//   console.log('addEventListener');
//   (window as any).addEventListener_ (...res);
// };
